import java.util.Arrays;
import java.util.LinkedList;

public class lk6258 {
    public static void main(String[] args) {
        int[] nums = new int[]{4,3,6,16,8,2};
        System.out.println(longestSquareStreak(nums));
    }
    public static int longestSquareStreak(int[] nums) {
        Arrays.sort(nums);
        int n =nums.length;
        int end=0;
        int m=0;
        int max=0;
        for(int i=0;i<n;i++){
            if(nums[i]==0){
                continue;
            }else {
                m=nums[i];
                nums[i]=0;
                end=1;
                while(true){
                    int a=Arrays.binarySearch(nums, m*m);
                    if(a<=i){
                        break;
                    }
                    m=nums[a];
                    end+=1;
                    nums[a]=0;
                }
                if(max<end){
                    max=end;
                }
                end=0; 
            }
        }
        if(max==1){
            return -1;
        }else {
            return max;
        }
    }
}
